package cn.ms.neural.common.log;

import cn.ms.neural.common.log.impl.JdkLoggerFactory;
import cn.ms.neural.common.log.impl.Log4j2LoggerFactory;

public class LogCollector {

	public static interface InternalLoggerFactory {
		ILog getLogger(Class<?> clazz);
		ILog getLogger(String name);
	}

	private static InternalLoggerFactory factory;

	static {
		initDefaultFactory();
	}

	public static void setLoggerFactory(InternalLoggerFactory factory) {
		if (factory != null) {
			LogCollector.factory = factory;
		}
	}

	public static ILog getLogger(Class<?> clazz) {
		return factory.getLogger(clazz);
	}

	public static ILog getLogger(String name) {
		return factory.getLogger(name);
	}

	public static void initDefaultFactory() {
		if (factory != null) {
			return;
		}

		try {
			factory = new Log4j2LoggerFactory();
			return;
		} catch (Throwable t) {
			if (factory == null) {
				factory = new JdkLoggerFactory();
			}
		}
	}

}
